import Util;
import RPC;
import EndpointUtil;

extends RPC;

init(config: RPC.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('pailabel', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

model GetDatasetRequest = {
  datasetId: long(name='DatasetId'),
}

model GetDatasetResponse = {
  requestId: string(name='RequestId'),
  errMsg: string(name='ErrMsg'),
  errCode: integer(name='ErrCode'),
  success: boolean(name='Success'),
  code: string(name='Code'),
  data: {
    id: long(name='Id'),
    userId: string(name='UserId'),
    ownerId: string(name='OwnerId'),
    name: string(name='Name'),
    storageType: string(name='StorageType'),
    registerType: string(name='RegisterType'),
    storagePath: string(name='StoragePath'),
    dataType: string(name='DataType'),
    sourcePath: string(name='SourcePath'),
    status: string(name='Status'),
    gmtCreate: string(name='GmtCreate'),
    utcCreate: string(name='UtcCreate'),
    gmtModified: string(name='GmtModified'),
    utcModified: long(name='UtcModified'),
    uid: string(name='Uid'),
    taskId: long(name='TaskId'),
    tmpDownloadUrl: string(name='TmpDownloadUrl'),
    tags: [ map[string]any ](name='Tags'),
  }(name='Data'),
}

async function getDatasetWithOptions(request: GetDatasetRequest, runtime: Util.RuntimeOptions): GetDatasetResponse {
  Util.validateModel(request);
  return doRequest('GetDataset', 'HTTPS', 'POST', '2020-06-08', 'AK', null, request, runtime);
}

async function getDataset(request: GetDatasetRequest): GetDatasetResponse {
  var runtime = new Util.RuntimeOptions{};
  return getDatasetWithOptions(request, runtime);
}

model ListDatasetsRequest = {
  pageNumber: integer(name='PageNumber'),
  pageSize: integer(name='PageSize'),
  nameLike?: string(name='NameLike'),
}

model ListDatasetsResponse = {
  requestId: string(name='RequestId'),
  errMsg: string(name='ErrMsg'),
  errCode: integer(name='ErrCode'),
  success: boolean(name='Success'),
  code: string(name='Code'),
  data: {
    pageIndex: integer(name='PageIndex'),
    pageSize: integer(name='PageSize'),
    totalNum: integer(name='TotalNum'),
    totalPages: integer(name='TotalPages'),
    data: [ map[string]any ](name='Data'),
  }(name='Data'),
}

async function listDatasetsWithOptions(request: ListDatasetsRequest, runtime: Util.RuntimeOptions): ListDatasetsResponse {
  Util.validateModel(request);
  return doRequest('ListDatasets', 'HTTPS', 'POST', '2020-06-08', 'AK', null, request, runtime);
}

async function listDatasets(request: ListDatasetsRequest): ListDatasetsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listDatasetsWithOptions(request, runtime);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
